Merged
Conversation
KwonNayeon
reviewed
Feb 19, 2025
Contributor
Author
|
#287 은 어떻게 풀어야할지 생각이 안나서 다음주 문제풀 때 해결해보겠습니다. |
KwonNayeon
approved these changes
Feb 21, 2025
Comment on lines
+1
to
+6
| /** | ||
| * Source: https://www.lintcode.com/problem/178/ | ||
| * Solution: 유효한 트리인지 순회하면서 확인하면 되기에 BFS로 구현 | ||
| * 시간 복잡도: O(V + E) - 노드와 간선에 한번은 방문 | ||
| * 공간 복잡도: O(V + E) - 인접리스트 만큼의 공간 필요 | ||
| */ |
Contributor
There was a problem hiding this comment.
주석을 자세히 적어주셔서, 익숙하지 않은 언어인데도 알고리즘을 이해하기 수월했습니다!
Comment on lines
+26
to
+55
| function reorderList(head: ListNode | null): void { | ||
| if (!head || !head.next) return; | ||
|
|
||
| // 1. 모든 노드를 배열에 저장 | ||
| const nodes: ListNode[] = []; | ||
| let current: ListNode | null = head; | ||
| while (current) { | ||
| nodes.push(current); | ||
| current = current.next; | ||
| } | ||
|
|
||
| // 2. 배열의 양끝에서 시작하여 리스트 재구성 | ||
| let left = 0; | ||
| let right = nodes.length - 1; | ||
|
|
||
| while (left < right) { | ||
| // 현재 왼쪽 노드의 다음을 저장 | ||
| nodes[left].next = nodes[right]; | ||
| left++; | ||
|
|
||
| if (left === right) break; | ||
|
|
||
| // 현재 오른쪽 노드를 다음 왼쪽 노드에 연결 | ||
| nodes[right].next = nodes[left]; | ||
| right--; | ||
| } | ||
|
|
||
| // 마지막 노드의 next를 null로 설정 | ||
| nodes[left].next = null; | ||
| } |
Contributor
There was a problem hiding this comment.
공간복잡도 개선을 위해 slow/fast 포인터를 사용한 방법도 도전해보시면 좋을 것 같습니다!
Contributor
There was a problem hiding this comment.
@mike2ox 님 이번 주도 고생하셨습니다! 주석을 꼼꼼하게 적어주셔서 코드 리뷰가 수월했고, 공부도 많이 되었습니다. 덕분에 "Maximum depth of binary tree"를 반복문으로 접근해볼 수 있었습니다 😄
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
답안 제출 문제
체크 리스트
In Review로 설정해주세요.